﻿using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Elifart.Library.Serialization
{
    public static class ObjectReader
    {
        #region Static Methods

        public static T Load<T>(string filePath)
        {
            Stream stream = File.Open(filePath, FileMode.Open);
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            Object loadedObject = binaryFormatter.Deserialize(stream);
            binaryFormatter = null;
            stream.Flush();
            stream.Close();

            return (T)loadedObject;
        }

        #endregion
    }
}
